#ifndef NOTIFICATIONCENTER_H
#define NOTIFICATIONCENTER_H

#include <QObject>
#include <list>
#include <QHash>
#include <mutex>
#include <QByteArray>

#include "NotifyInterface.h"

class NotificationCenter
{
public:
    NotificationCenter(){}

    static NotificationCenter &get();

    bool addObserver(const QString &nameId, const NotifyInterface &t);
    bool removeObserver(const QString &nameId, const NotifyInterface & t);

    // 移除该类型所有
    bool removeObserver(const NotifyInterface & t);

    void postNofication(const QString &name,const QByteArray &);
private:
    /* 标识和回调是多对多关系 */
    QHash<QString,std::list<NotifyInterface> > m_objs;
    std::mutex m_lock;

};

#endif // NOTIFICATIONCENTER_H
